using CoreProject.DTO;
using CoreProject.IRepository;
using CoreProject.IService;
using CoreProject.Model;

namespace CoreProject.Service
{
    public class UsersService : BaseService<User>, IUsersService
    {
        private readonly IUsersRepository _repoistory;

        public UsersService(IUsersRepository repoistory) : base(repoistory)
        {
            _repoistory = repoistory;
        }

        public async Task<List<MonthStatisticsDto>> GetMonthStatistics(int starMonth, int endMonth)
        {
            return await _repoistory.GetMonthStatistics(starMonth, endMonth);
        }

        public async Task<User> GetUser(int id)
        {
            return await _repoistory.GetUser(u => u.UserId == id);
        }

        public async Task<List<User>> GetUsers()
        {
            return await _repoistory.GetUsers(u => true);
        }

        public async Task<(List<User> list, int count)> GetUsersByPage(int page, int size, string name)
        {
            return await _repoistory.GetUsersByPage<int>(page, size, true, u => u.UserId, u => u.UserName.Contains(name));
        }

        public async Task<User> Login(string loginName, string loginPwd)
        {
            return await _repoistory.GetUser(u => u.LoginName == loginName && u.LoginPwd == loginPwd);
        }

        public async Task<(List<User> list, int count)> VipList(string name, int page, int size)
        {
            return await _repoistory.VipList<int>(name,page, size, true, u => u.UserId);
        }
    }
}
